package dao.impl;

import dao.BaseDao;
import dao.OrderInfoDao;
import entity.OrderInfo;
import entity.Userinfo;
import vo.OrderInfoVo;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class OrderInfoDaoImpl extends BaseDao implements OrderInfoDao {

    /**
     * 查询订单详情
     * @param id
     * @return
     */
    @Override
    public List<OrderInfoVo> selectAll(int id) {
        List<OrderInfoVo> list=new ArrayList<>();
        OrderInfoVo o=null;
        String sql="select a.id,s.file_path,s.goodsName,o.order_numder,s.price,s.`describe`,a.quantity,(a.quantity*s.price) upmoneys,s.units from order_info a join goods s on s.goodsID=a.goodsID join orders o on o.orderID=a.ordersID where ordersID=?";
        ResultSet rs=null;
        Connection conn=null;
        PreparedStatement ps=null;
        try {
            rs=exeQuery(sql, new Object[]{
                    id
            },conn,ps);
            while (rs.next()){
                o=new OrderInfoVo();
                o.setId(rs.getInt(1));
                o.setFilePath(rs.getString(2));
                o.setGoodsName(rs.getString(3));
                o.setOrderNumder(rs.getString(4));
                o.setPrice(rs.getDouble(5));
                o.setDescribe(rs.getString(6));
                o.setQuantity(rs.getInt(7));
                o.setUpmoneys(rs.getDouble(8));
                o.setUnits(rs.getString(9));
                list.add(o);
            }
        } catch (Exception exception) {
            exception.printStackTrace();
        }finally {
            closeAll(rs,ps,conn);
        }
        return list;
    }
}
